package gulimall.threadReview;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author HLF
 * @date 2022/7/22 21:11
 */
public class ThreadReview01 {
    public static void main(String[] args) {
        FutureTask<Integer> futureTask = new FutureTask<>(new MyThread());

        Thread thread = new Thread(futureTask, "分支线程");

        thread.start();

        Integer result = null;
        try {
            result = futureTask.get();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        System.out.println(result);
    }
}


class MyThread implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println("线程Id：" + Thread.currentThread().getId() + ",当前线程名：" + Thread.currentThread().getName() + ",线程开始...");

        int a = 1;
        int b = 2;

        System.out.println("线程Id：" + Thread.currentThread().getId() + ",当前线程名：" + Thread.currentThread().getName() + ",线程结束...");
        return a + b;
    }
}